package com.xyyl.patient.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.google.gson.annotations.Until;
import com.xyyl.patient.entity.evaluating.EvaluatingUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.xyyl.patient.core.controller.BaseController;
import com.xyyl.patient.core.support.Pager;
import com.xyyl.patient.core.util.ResponseBodyResult;
import com.xyyl.patient.entity.evaluating.Evaluating;
import com.xyyl.patient.entity.evaluating.EvaluatingQuestionVO;
import com.xyyl.patient.entity.evaluating.EvaluatingType;
import com.xyyl.patient.service.evaluating.EvaluatingService;


/**
 * @projectName:xyyl-oms-server
 * @ClassName: Evaluating
 * @Description:Evaluating
 * @author kellie
 * @date 2018-01-03 14:41:05
 */
 
@RestController
@RequestMapping("/evaluating")
public class EvaluatingController extends BaseController  {

    
	@Autowired
	private EvaluatingService evaluatingService;

	/*
	* 获取心里自测列表
	* */
	@RequestMapping(value = "/getEvaluatingIndex", method = RequestMethod.POST)
	public JSONObject getEvaluatingIndex() {
		Pager pager = super.initPage();
		/* 分类*/
		List<EvaluatingType> evaluatingCategoriesList = evaluatingService.getEvaluatingCategories();
		/*下面的列表*/
		List<Evaluating> evaluatingList =evaluatingService.getEvaluating(pager);

		 Map<String,Object> mapResult =Maps.newHashMap();
		mapResult.put("evaluatingCategoriesList", evaluatingCategoriesList);
		mapResult.put("evaluatingList", evaluatingList);
		return ResponseBodyResult.success(mapResult);
	}
	/*
	* 获取心里自测单个
	* */
	@RequestMapping(value = "/getEvaluatingInfo", method = RequestMethod.POST)
	public JSONObject getEvaluatingInfo(@RequestParam Integer EvaluatingId) {

		Evaluating evaluating =evaluatingService.queryObject(EvaluatingId);
		return ResponseBodyResult.success(evaluating);
	}
	/*
	* 获取自测 题目以及 答案
	* */
	@RequestMapping(value = "/getEvaluatingQuestion", method = RequestMethod.POST)
	public JSONObject getEvaluatingQuestion(@RequestParam Integer EvaluatingId) {

		List<EvaluatingQuestionVO> evaluatingQuestionVOS =evaluatingService.getEvaluatingQuestion(EvaluatingId);
		return ResponseBodyResult.success(evaluatingQuestionVOS);
	}


	/*
	* 查询自测结果
	* */
	@RequestMapping(value = "/getEvaluatingAnswer", method = RequestMethod.POST)
	public JSONObject getEvaluatingAnswer(@RequestParam Integer EvaluatingId,@RequestParam Integer score) {

		Evaluating evaluating =  evaluatingService.getEvaluatingAnswer(EvaluatingId,score);
		return ResponseBodyResult.success(evaluating);
	}

	/*
	* 提交自测的答案
	* */
	@RequestMapping(value = "/addEvaluatingAnswer", method = RequestMethod.POST)
	public JSONObject addEvaluatingAnswer(@RequestParam Integer EvaluatingId,@RequestParam Integer score,@RequestParam Integer patientid) {
		EvaluatingUser evaluatingUser = new EvaluatingUser();
		String nowDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()).toString();
		evaluatingUser.setAddtime(nowDate);
		evaluatingUser.setPatientid(patientid);
		evaluatingUser.setScore(score);
		evaluatingUser.setEvaluatingId(EvaluatingId);
		int result =  evaluatingService.setEvaluatingAnswer(evaluatingUser);
		return ResponseBodyResult.success(result);
	}

	/*
        * 获取我的自测
        * */
	@RequestMapping(value = "/getEvaluatingUserList", method = RequestMethod.POST)
	public JSONObject addEvaluatingAnswer(@RequestParam Integer patientid) {
		List<Evaluating> evaluatingList =evaluatingService.getEvaluatingByUser(patientid);
		return ResponseBodyResult.success(evaluatingList);
	}





}
